/**
 * Copyright (c) 2011, www.quartzsource.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.quartzsource.core

trait Repository {
  val capabilities: Set[String]
  val supportedformats: Set[String]
  val supported: Set[String]

  /**
   * tell whether repo supports named capability.
   * return false if not supported.
   */
  def capable(name: String): Boolean = {
    capabilities.contains(name)
  }

  /**
   * throw an exception if the given capability is not present
   */
  def requireCapability(name: String, purpose: String) {
    if (!capable(name)) throw new CapabilityException(translate(
      "cannot %s; remote repository does not support the %s capability", purpose, name))
  }

  def local: Boolean = false

  def canCopy: Boolean = local

  def close = {}

  def url: String

  def baseEnvironment: QEnvironment
  def environment: QEnvironment
}

trait RepoFactory {
  def instantiate(env: QEnvironment, path: QURL, create: Boolean = false): Repository
}

